/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.regions;

import java.io.Serializable;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;

/**
 * Defines a location with a country, region, city
 * @author W4L3
 */
@Embeddable
public class Location implements Serializable
{

	 /**
	  * The country of the location
	  */
	 @Embedded
	 private Country country;

	 /*
	  * The region of the location
	  */
	 @Embedded	 
	 private Region region;
	 
	 /*
	  * The city of the location
	  */
	 private String city;


	 /**
	  * Initiates a location with the country, region and city all null
	  */
	 public Location()
	 {
	 }

	 /**
	  * Initiate a Location with a country, region and city
	  * @param country the country
	  * @param region the region
	  * @param city  the city
	  */
	 public Location(Country country, Region region, String city)
	 {
		  this.country = country;
		  this.region = region;
		  this.city = city;
	 }


	 /**
	  * Gets the country of the location
	  * @return the country.  Returns null if no country was ever set
	  */
	 public Country getCountry()
	 {
		  return this.country;
	 }

	 /**
	  * Gets the region of the location.
	  * @return the region.  Returns null if no region was ever set.
	  */
	 public Region getRegion()
	 {
		  return this.region;
	 }

	 /**
	  * Gets the city of the location.
	  * @return the city.  Returns null of no region was ever set.
	  */
	 public String getCity()
	 {
		  return this.city;
	 }

	 /**
	  * Sets the country of this location
	  * @param country the country
	  */
	 public void setCountry(Country country)
	 {
		  this.country = country;
	 }

	 
	 /**
	  * Sets the region of this region
	  * @param region the region
	  */
	 public void setRegion(Region region)
	 {
		  this.region = region;
	 }

	 /**
	  * Sets the city of this location
	  * @param city the city
	  */
	 public void setCity(String city)
	 {
		  this.city = city;
	 }
	 
	 /**
	  * Compares this Location to another location
	  * @param o
	  * @return true if the object is an instance of Location type, and whose country, region and city name match with this object.
	  */
	 @Override
	 public boolean equals (Object o)
	 {
		  if (! (o instanceof Location))
		  {
			   return false;
		  }
		  
		  Location loc = (Location) o;
				
		  return city.equals(loc.getCity()) && region.equals(loc.getRegion())  && country.equals(loc.getCountry());
	 }
	 
	 public String toString ()
	 {
		  return city + ", " + region.getRegionName() + ", " + country.getCountryName();
	 }

}